/**
*@ClassName: AppTestController
*@Description
*@Author maozhi
*@Date 2021/3/22
*@Time 14:59
*/

package com.universityJob.modules.app.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.universityJob.common.utils.PageUtils;
import com.universityJob.modules.app.annotation.Login;
import com.universityJob.modules.app.annotation.LoginUser;
import com.universityJob.common.utils.R;
import com.universityJob.modules.app.entity.UserEntity;
import com.universityJob.modules.app.service.UserService;
import com.universityJob.modules.data.entity.DataJobEntity;
import com.universityJob.modules.data.entity.DataRecEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * APP测试接口
 *
 *
 */
@RestController
@RequestMapping("/app")
@Api("APP接口")
public class AppController {

    @Autowired
    private UserService userService;


    @Login
    @GetMapping("userInfo")
    @ApiOperation("获取用户信息")
    public R userInfo(@LoginUser UserEntity user){
        return R.ok().put("user", user);
    }
//    @Login
//    @GetMapping("updateUserInfo")
//    @ApiOperation("获取用户信息")
//    public R updateUserInfo(@RequestParam ){
//        return R.ok().put("user", user);
//    }

    @Login
    @GetMapping("getHistoryRecommends")
    @ApiOperation("获取历史推送信息")
    public R findRecommends(@RequestParam(required=false) Map recommends,@LoginUser UserEntity user){
        String username = user.getUsername();
        recommends.put("username",username);
        R r = userService.findRecommends(recommends);
        return r;
    }
    @Login
    @GetMapping("upRecommendsStatus/{id}")
    @ApiOperation("修改推送消息为已读")
    public R upRecommendsStatus(@PathVariable("id") String id){
        R r = userService.upRecommendsStatus(id);
        return r;
    }
    @Login
    @PostMapping("updateUserInfo")
    @ApiOperation("获取用户ID更新信息")
    public R userInfo(@RequestParam(required=false) Map userr,@RequestAttribute("userId") String userId){
        UserEntity user = JSON.parseObject(JSON.toJSONString(userr), UserEntity.class);
        user.setUserId(userId);
        boolean update = userService.updateById(user);
        if (update){
            return R.ok("修改信息成功！");
        }else {
            return R.error("修改信息失败！");
        }
    }

    @GetMapping("getAllOlympiad")
    @ApiOperation("获取所有届数")
    public R getAllOlympiad(){
        R r = userService.getAllOlympiad();
        return r;
    }
    @GetMapping("getRecList")
    @ApiOperation("获取企业列表")
    public R getRecList(@RequestParam(required=false) Map rec){
        Page<DataRecEntity> recList = userService.getRecList(rec);
        return R.ok().put("page",recList);
    }

    @GetMapping("getJobList")
    @ApiOperation("获取职位列表")
    public R getJobList(@RequestParam(required=false) Map job){
        R r = userService.getJobList(job);
        return r;
    }
    @GetMapping("getHistoryList")
    @ApiOperation("获取历史就业信息")
    public R getHistoryList(@RequestParam(required=false) Map stu){
        R r = userService.getHistoryList(stu);
        return r;
    }

    @GetMapping("getOneJob/{id}")
    @ApiOperation("获取职位信息")
    public R getOneJob(@PathVariable("id") String id){
        R r = userService.getOneJob(id);
        return r;
    }

    @GetMapping("getOneRec/{id}")
    @ApiOperation("获取企业信息")
    public R getOneRec(@PathVariable("id") String id){
        R r = userService.getOneRec(id);
        return r;
    }

}
